package ar.com.ford.it.fullEconomics.persistence.dao;

import java.sql.Timestamp;
import java.util.Collection;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesx01Intfsource;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesx02Fileconten;
import ar.com.ford.it.webengine.persistence.PersistenceUtil;
import com.ford.it.logging.ILogger;
import com.ford.it.logging.LogFactory;
import com.ford.it.persistence.PersistenceException;
import com.ford.it.persistence.PersistenceManager;
import com.ford.it.persistence.Query;
import com.ford.it.persistence.Transaction;

public class WorkerFileDao extends Dao {
    private static final String CLASS_NAME = SupplierDao.class.getName();
    private static final ILogger log = LogFactory.getInstance().getLogger(
            CLASS_NAME);
    
    
    public Collection<Teesx01Intfsource> findIntfSourceByFlag(String[] flag) throws PersistenceException {
        

    	String METHOD_NAME = "findIntfSourceByFlag";
		log.entering(CLASS_NAME, METHOD_NAME);

		Collection<Teesx01Intfsource> resultCol = null;
		PersistenceManager pm = null;

		pm = PersistenceUtil.getPersistenceManager();
		Query query = pm
				.newQuery("findIntfSourceByFlag", Teesx01Intfsource.class);		

		query.setParameters(flag);

		resultCol = (Collection) pm.executeQuery(query);

		log.exiting(CLASS_NAME, METHOD_NAME);
		return resultCol;

        
    }
    
    
    /**
	 * Da de alta el FileConten pasado por parametro
	 * 
	 * @param fileconten
	 */
	public void createFileConten(Teesx02Fileconten teesx02Fileconten)
			throws PersistenceException {

		String METHOD_NAME = "createFileConten";
		log.entering(CLASS_NAME, METHOD_NAME);

		Transaction tx = null;

		tx = PersistenceUtil.getTransaction();
		tx.registerInsert(teesx02Fileconten);

		log.exiting(CLASS_NAME, METHOD_NAME);
	}
	
    /**
	 * Da de alta el FileConten pasado por parametro
	 * 
	 * @param fileconten
	 */
	public Collection<Teesx02Fileconten> findFilesByProcessStatus(String status, Teesx01Intfsource intfSource, Timestamp dateFrom, Timestamp dateTo)  throws PersistenceException {
		
	   	String METHOD_NAME = "findFilesByProcessStatus";
		log.entering(CLASS_NAME, METHOD_NAME);

		Collection<Teesx02Fileconten> resultCol = null;
		
		PersistenceManager pm = null;

		pm = PersistenceUtil.getPersistenceManager();
		Query query = pm
				.newQuery("findFilesByProcessStatusQuery", Teesx02Fileconten.class);		

		Object[] parametros = { intfSource, dateFrom, dateTo, status };
		
		query.setParameterArray(parametros);

		resultCol = (Collection<Teesx02Fileconten>) pm.executeQuery(query);
		
		log.exiting(CLASS_NAME, METHOD_NAME);
		
		return resultCol;
	}
	
}
